/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.service;

import com.bifrost.common.base.ServerResponse;
import com.bifrost.dto.AssignedProductOptionDTO;
import com.bifrost.entity.*;
import com.bifrost.entity.ProductService;
import com.bifrost.model.SkuModel;
import com.bifrost.model.ro.ProductImgUploadRO;
import com.bifrost.model.vo.PageVO;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author joewee
 * @version 1.0.0
 * @Date 2017/10/29 13:42
 */
public interface ProductSkuService {
    /**
     * 获取sku指定类型的所有附属品
     *
     * @param sku  sku
     * @param type SERVICE-服务、GIFT-赠品、UPKEEP-保养搭配
     * @return
     */
    List<ProductSku> getAssociationsByType(ProductSku sku, String type);

    /**
     * 获取sku所有附属服务
     *
     * @param sku sku
     * @return
     */
    List<ProductService> getAssociationsOfService(ProductSku sku);

    /**
     * 获取sku所有附属的保养搭配商品
     *
     * @param sku
     * @return
     */
    List<ProductSku> getAssociationsOfUpkeep(ProductSku sku);

    /**
     * 获取sku所有的附属礼品
     *
     * @param sku
     * @return
     */
    List<ProductSku> getAssociationsOfGift(ProductSku sku);

    /**
     * 检查sku是否可用
     *
     * @param sku
     * @return
     */
    boolean isAvailable(ProductSku sku);

    /**
     * 查询id对应的sku商品
     *
     * @param id skuId
     * @return
     */
    ProductSku getSkuById(Long id);

    /**
     * 返回sku主要图片
     *
     * @param productSku
     * @return
     */
    List<String> getSkuPrimaryMedias(ProductSku productSku);

    /**
     * 查询商品sku默认图片
     *
     * @param sku
     * @return
     */
    Media getSkuDefaultMedia(ProductSku sku);

    /**
     * 查询商品sku默认图片: sku为默认sku
     *
     * @param sku
     * @return
     */
    String getSkuDefaultMeda(ProductSku sku);

    /**
     * 返回默认sku图片
     *
     * @param sku
     * @return
     */
    String getDefaultSkuMedia(ProductSku sku);

    /**
     * 返回所有默认SKU PRIMARY图片
     *
     * @param sku
     * @return
     */
    List getDefaultSkuPrimaryMedias(ProductSku sku);

    Media getSkuDefaultMedia(Long skuId);

    /**
     * 保存sku
     *
     * @param sku
     * @return
     */
    ProductSku saveSku(ProductSku sku);

    /**
     * 计算绑定商品价格
     *
     * @param sku
     */
    void pricingBundleProduct(ProductSku sku);


    /**
     * 获取sku相关赠品和服务
     *
     * @param sku sku
     * @return Map
     */
    Map getSkuGiftAndService(ProductSku sku);

    /**
     * 增加商品累计销售数量
     *
     * @param skuId
     * @param quantity
     * @return
     */
    ProductSku incrementSalesQuantity(Long skuId, Integer quantity);

    /**
     * 减少商品累计销售数量
     *
     * @param skuId
     * @param quantity
     * @return
     */
    ProductSku decrementSalesQuantity(Long skuId, Integer quantity);

    /**
     * 获取商品对应的规格属性以及sku
     *
     * @param productId
     * @return
     */
    List<AssignedProductOptionDTO> findAssignedProductOptionsByProductId(Long productId);

    /**
     * 获取商品对应的规格属性以及sku
     * @param product
     * @return
     */
    List<AssignedProductOptionDTO> findAssignedProductOptionsByProduct(Product product);

    /**
     * 商品某属性的计数
     * @param productOptionId
     * @return
     */
    Long countProductsUsingProductOptionById(Long productOptionId);

    /**
     * 查询所有具有某属性的商品id
     * @param productOptionId
     * @param start
     * @param pageSize
     * @return
     */
    List<Long> findProductIdsUsingProductOptionById(Long productOptionId, int start, int pageSize);

    /**
     * 获取所有sku，当商品有规格属性时过掉滤默认sku
     *
     * @param product
     * @return
     */
    List<SkuModel> getAllSku(Product product);

    /**
     * 获取sku多规格属性map
     * <p>
     *     skus->获取sku列表包含规格属性,options->规格类目列表
     * </p>
     * @param product
     * @return
     */
    Map getSkusMap(Product product);
    /**
     * sku to skuModel
     *
     * @param sku
     * @return
     */
    SkuModel convertToSkuModel(ProductSku sku);

    /**
     * 返回默认sku
     *
     * @param productSkuId
     * @return
     */
    ProductSku getDefaultSku(Long productSkuId);

    /**
     * 返回默认sku
     *
     * @param productSku
     * @return
     */
    ProductSku getDefaultSku(ProductSku productSku);

    ProductSku getByExternalId(String externalId);

    PageVO findSkuHot(int page, int pageSize);

    int updateSkuHot(String ids, Boolean hot);

    /**
     * 返回sku规格描述、eg：黑色/XXl
     *
     * @param productSkuId productSkuId
     * @return option
     */
    String getSkuOptions(Long productSkuId);
}

